package com.baizhi.service.impl;

import com.baizhi.dao.CmfzAudioDao;
import com.baizhi.entity.CmfzAudio;
import com.baizhi.service.CmfzAudioService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CmfzAudioServiceImpl implements CmfzAudioService {
    @Autowired
    private CmfzAudioDao cmfzAudioDao;
    @Override
    @Transactional(readOnly = true)
    public Page<CmfzAudio> selectByAlbumId(Integer albumId,Integer page,Integer limit) {
        Page<CmfzAudio> cmfzAudioPage = new Page<>(page, limit);
        //根据音频所属的专辑id查询   准备查询条件对象
        QueryWrapper<CmfzAudio> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("album_id",albumId);
        Page<CmfzAudio> selectPage = cmfzAudioDao.selectPage(cmfzAudioPage, queryWrapper);
        return selectPage;
    }

    @Override
    public void insertCmfzAudio(CmfzAudio cmfzAudio) {
        cmfzAudioDao.insert(cmfzAudio);
    }

    @Override
    public void deleteCmfzAudio(Integer id) {
        cmfzAudioDao.deleteById(id);
    }

    @Override
    @Transactional(readOnly = true)
    public CmfzAudio selectById(Integer id) {
        return cmfzAudioDao.selectById(id);
    }

    @Override
    public void updateCmfzAudio(CmfzAudio cmfzAudio) {
        cmfzAudioDao.updateById(cmfzAudio);
    }
}
